package cn.kgc.crowdfundingadminspringboot.service;

import cn.kgc.crowdfundingadminspringboot.mapper.CertMapper;
import cn.kgc.crowdfundingadminspringboot.pojo.Cert;
import cn.kgc.crowdfundingadminspringboot.pojo.CertExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CertServiceImpl implements CertService {
    @Resource
    CertMapper certMapper;
    @Override
    public PageInfo<Cert> queryForKeywordWithPage(Integer pageNum, Integer pageSize, String keyword) {
        // 1.开启分页功能
        PageHelper.startPage(pageNum, pageSize);

        // 2.执行查询
        CertExample certExample=new CertExample();
        CertExample.Criteria criteria = certExample.createCriteria();
        criteria.andNameLike("%"+keyword+"%");
        List<Cert> list = certMapper.selectByExample(certExample);
        // 3.封装为PageInfo对象
        return new PageInfo<>(list);
    }

    @Override
    public List<Cert> getCertListByIdList(List<Integer> certIdList) {
        CertExample certExample=new CertExample();
        certExample.createCriteria().andIdIn(certIdList);
        return certMapper.selectByExample(certExample);
    }

    @Override
    public void batchRemove(List<Integer> certIdList) {
        CertExample certExample=new CertExample();
        certExample.createCriteria().andIdIn(certIdList);
        certMapper.deleteByExample(certExample);
    }

    @Override
    public void saveCert(String CertName) {
        certMapper.insert(new Cert(null,CertName));
    }

    @Override
    public void updateCert(Cert cert) {
    certMapper.updateByPrimaryKey(cert);
    }
}
